
#include "strategies/PointIncProbKnockingStrategy.h"
#include "Query.h"

bool PointIncProbKnockingStrategy::decideKnock(CCardStack* hand, const GameState* gameState) {
    int increaseProbability = 0;
    // Consider picking from discard; the value increase can be obtained deterministically
    const CCard& pileCard = gameState->getCardsInDiscard().back();
    if (Query::maxGainFromCard(*hand, CCard(pileCard.GetIndex())) > 0) {
        // The value of the hand can be increased
        increaseProbability = 100;
    }
    else {
        // Consider the increase probability by drawing
        CCardStack possibleCards = gameState->getUnknownCards(gameState->getCurrPlayer());
        if (possibleCards.Size() > 0) {
            int increasingCards = 0;
            for (CONST_VI ci = possibleCards.begin(); ci != possibleCards.end(); ci++) {
                if (Query::maxGainFromCard(*hand, CCard(ci->GetIndex())) > 0) {
                    increasingCards++;
                }
            }
            increaseProbability = (int) (100 * ((float) increasingCards / possibleCards.Size()));
        }
    }
    bool knock = (increaseProbability < probabilityThreshold);
    if (knock) {
        decisionCertainty = 100 - increaseProbability;
    }
    else {
        decisionCertainty = increaseProbability;
    }
    Query::debugOut(string("Knocking decision certainty: "), 2);
    Query::debugValue(decisionCertainty, 2);
    return knock;
}
